package vip.specimen.system.datasource.validation.implement;

import vip.specimen.system.datasource.entity.SystemPermissionEntity;
import vip.specimen.system.datasource.validation.annotation.PermissionUuid;
import vip.specimen.system.service.SystemPermissionService;

import javax.annotation.Resource;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * *@Author: 余浪人
 * *@Date：2021/3/22 14:54
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
public class PermissionUuidImp implements ConstraintValidator<PermissionUuid, Set<UUID>> {
    @Resource
    private SystemPermissionService permissionService;

    @Override
    public boolean isValid(Set<UUID> list, ConstraintValidatorContext constraintValidatorContext) {
        List<SystemPermissionEntity> permissionEntitys = this.permissionService.findAllById(list);
        return (list.size() == permissionEntitys.size()) && !permissionEntitys.contains(null);
    }
}